﻿
Public Class Form1

    Dim blnMouseDown, blnKeyDown, blnOperation As Boolean
    Dim strURL, strUserState, strClipboardURL As String
    Dim thrdURLThread As System.Threading.Thread
    Public URLShorteners(37) As URLShortener

    Public Class URLShortener
        Public strShortenerURL As String = vbNullString
        Public chkCheckbox As ShortenerCheckboxes = New ShortenerCheckboxes
        Public strAPIURL As String = vbNullString
        Public blnNeedsSpecificShorten As Boolean = False
        Public blnEncodeURL As Boolean = True
        Public intLineNumber As Integer = 0
        Public strURLPrefix As String = vbNullString

        Private Function GetSettingString() As String
            Dim strSetting As String = strShortenerURL.Replace(".", "_")
            If IsNumeric(strSetting.Chars(0)) = True Then
                strSetting = "_" & strSetting
            End If
            Return strSetting
        End Function

        Public Function EnabledSetting() As Boolean
            Return My.Settings(GetSettingString())
        End Function

        Public Sub SaveSetting()
            My.Settings(GetSettingString()) = chkCheckbox.Checked
        End Sub

        Public Function ShortenURL(ByVal strURLtoShorten As String) As String
            Dim strEncodedURL As String = System.Web.HttpUtility.UrlEncode(strURLtoShorten)
            Try
                If blnNeedsSpecificShorten = False Then
                    Dim srStreamReader As System.IO.StreamReader
                    If blnEncodeURL = True Then
                        srStreamReader = New System.IO.StreamReader(System.Net.HttpWebRequest.Create(strAPIURL & strEncodedURL).GetResponse().GetResponseStream())
                    Else
                        srStreamReader = New System.IO.StreamReader(System.Net.HttpWebRequest.Create(strAPIURL & strURLtoShorten).GetResponse().GetResponseStream())
                    End If
                    For intCounter As Integer = 0 To intLineNumber - 1
                        srStreamReader.ReadLine()
                    Next
                    Return strURLPrefix & srStreamReader.ReadLine
                Else
                    Dim strTempString As String
                    Select Case strShortenerURL
                        Case "arm.in"
                            Dim srStreamReader As New System.IO.StreamReader(System.Net.HttpWebRequest.Create(strAPIURL & strURLtoShorten).GetResponse.GetResponseStream)
                            For intCounter As Integer = 1 To 3
                                If intCounter <> 3 Then
                                    srStreamReader.ReadLine()
                                Else
                                    strTempString = srStreamReader.ReadLine().Substring(23)
                                    strTempString = strTempString.Substring(0, strTempString.IndexOf("<"))
                                    Return "http://" & strTempString
                                End If
                            Next
                        Case "buk.me"
                            strTempString = New System.IO.StreamReader(System.Net.HttpWebRequest.Create(strAPIURL & strEncodedURL).GetResponse().GetResponseStream()).ReadLine()
                            Return strTempString.Substring(0, strTempString.IndexOf("<"))
                        Case "micurl.com"
                            strTempString = New System.IO.StreamReader(System.Net.HttpWebRequest.Create(strAPIURL & strEncodedURL).GetResponse().GetResponseStream()).ReadLine()
                            If strTempString <> "1" And strTempString <> "2" Then
                                Return "http://micurl.com/" & strTempString
                            Else
                                Return "Error"
                            End If
                        Case "r.im"
                            strTempString = New System.IO.StreamReader(System.Net.HttpWebRequest.Create(strAPIURL & strEncodedURL).GetResponse().GetResponseStream()).ReadToEnd()
                            If strTempString.IndexOf("h") <> -1 Then
                                Return strTempString.Substring(strTempString.IndexOf("h"))
                            Else
                                Return "Error"
                            End If
                        Case "sn.im"
                            Dim srStreamReader As New System.IO.StreamReader(System.Net.HttpWebRequest.Create(strAPIURL & strEncodedURL).GetResponse.GetResponseStream)
                            For intCounter As Integer = 1 To 33
                                If intCounter <> 33 Then
                                    srStreamReader.ReadLine()
                                Else
                                    strTempString = srStreamReader.ReadLine().Substring(26)
                                    strTempString = strTempString.Substring(0, strTempString.IndexOf(" ")).Replace("snipr.com", "sn.im")
                                    Return strTempString
                                End If
                            Next
                        Case "snurl.com"
                            Dim srStreamReader As New System.IO.StreamReader(System.Net.HttpWebRequest.Create(strAPIURL & strEncodedURL).GetResponse.GetResponseStream)
                            For intCounter As Integer = 1 To 33
                                If intCounter <> 33 Then
                                    srStreamReader.ReadLine()
                                Else
                                    strTempString = srStreamReader.ReadLine().Substring(26)
                                    strTempString = strTempString.Substring(0, strTempString.IndexOf(" "))
                                    Return strTempString
                                End If
                            Next
                        Case "z.pe"
                            strTempString = New System.IO.StreamReader(System.Net.HttpWebRequest.Create(strAPIURL & strEncodedURL).GetResponse().GetResponseStream()).ReadLine()
                            If strTempString.Substring(0, 5) <> "error" Then
                                Return "http://z.pe/" & strTempString.Substring(5)
                            Else
                                Return "Error"
                            End If
                        Case Else
                            Return "Error"
                    End Select
                End If
            Catch ThrewError As Exception When ThrewError.Message <> "Thread was being aborted."
                Return "Error"
            End Try
        End Function
    End Class

    Public Class ShortenerCheckboxes
        Inherits CheckBox
        Private Sub ShortenerCheckboxes_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.CheckedChanged
            If frmOptions.blnCheckingUncheckingBoxes = False Then
                Dim intCheckedShorteners As Integer
                For intCounter As Integer = 0 To Form1.URLShorteners.Length - 1
                    If Form1.URLShorteners(intCounter).chkCheckbox.Checked = True Then
                        intCheckedShorteners += 1
                    End If
                Next
                If intCheckedShorteners = Form1.URLShorteners.Length Then
                    frmOptions.chkSelectDeselectAll.CheckState = Windows.Forms.CheckState.Checked
                ElseIf intCheckedShorteners = 0 Then
                    frmOptions.chkSelectDeselectAll.CheckState = Windows.Forms.CheckState.Unchecked
                Else
                    frmOptions.chkSelectDeselectAll.CheckState = Windows.Forms.CheckState.Indeterminate
                End If
            End If
        End Sub
    End Class

    Private Sub InitializeURLShorteners()
        For intCounter As Integer = 0 To URLShorteners.Length - 1
            URLShorteners(intCounter) = New URLShortener
        Next
        Dim intCounter2 As Integer
        URLShorteners(intCounter2).strShortenerURL = "3.ly"
        URLShorteners(intCounter2).strAPIURL = "http://3.ly/?api=em5893833&u="
        intCounter2 += 1
        URLShorteners(intCounter2).strShortenerURL = "a.gd"
        URLShorteners(intCounter2).strAPIURL = "http://a.gd/?module=ShortURL&file=Add&mode=API&url="
        intCounter2 += 1
        URLShorteners(intCounter2).strShortenerURL = "a.nf"
        URLShorteners(intCounter2).strAPIURL = "http://a.nf/?module=ShortURL&file=Add&mode=API&url="
        intCounter2 += 1
        URLShorteners(intCounter2).strShortenerURL = "ad.ag"
        URLShorteners(intCounter2).strAPIURL = "http://mobiletinyurl.com/create/?url="
        URLShorteners(intCounter2).strURLPrefix = "http://"
        intCounter2 += 1
        URLShorteners(intCounter2).strShortenerURL = "arm.in"
        URLShorteners(intCounter2).strAPIURL = "http://arm.in/arminize/"
        URLShorteners(intCounter2).blnNeedsSpecificShorten = True
        intCounter2 += 1
        URLShorteners(intCounter2).strShortenerURL = "bit.ly"
        URLShorteners(intCounter2).strAPIURL = "http://api.bit.ly/shorten?version=2.0.1&format=text&login=gnintendo&apiKey=R_d9b6a87c77c3db06f32492f8d87e9b0c&longUrl="
        intCounter2 += 1
        URLShorteners(intCounter2).strShortenerURL = "buk.me"
        URLShorteners(intCounter2).strAPIURL = "http://buk.me/api.php?url="
        URLShorteners(intCounter2).blnNeedsSpecificShorten = True
        intCounter2 += 1
        URLShorteners(intCounter2).strShortenerURL = "chilp.it"
        URLShorteners(intCounter2).strAPIURL = "http://chilp.it/api.php?url="
        intCounter2 += 1
        URLShorteners(intCounter2).strShortenerURL = "cli.gs"
        URLShorteners(intCounter2).strAPIURL = "http://cli.gs/api/v1/cligs/create?url="
        intCounter2 += 1
        URLShorteners(intCounter2).strShortenerURL = "fwd4.me"
        URLShorteners(intCounter2).strAPIURL = "http://api.fwd4.me/?url="
        intCounter2 += 1
        URLShorteners(intCounter2).strShortenerURL = "gl.am"
        URLShorteners(intCounter2).strAPIURL = "http://gl.am/API::shorten?type=plain&url="
        intCounter2 += 1
        URLShorteners(intCounter2).strShortenerURL = "idek.net"
        URLShorteners(intCounter2).strAPIURL = "http://idek.net/c.php?idek-api=true&idek-ref=your_app&idek-anchor=anchortag&idek-url="
        intCounter2 += 1
        URLShorteners(intCounter2).strShortenerURL = "ir.pe"
        URLShorteners(intCounter2).strAPIURL = "http://ir.pe/?api=1&url="
        intCounter2 += 1
        URLShorteners(intCounter2).strShortenerURL = "is.gd"
        URLShorteners(intCounter2).strAPIURL = "http://is.gd/api.php?longurl="
        intCounter2 += 1
        URLShorteners(intCounter2).strShortenerURL = "j.mp"
        URLShorteners(intCounter2).strAPIURL = "http://api.j.mp/shorten?version=2.0.1&format=text&login=gnintendo&apiKey=R_d9b6a87c77c3db06f32492f8d87e9b0c&longUrl="
        intCounter2 += 1
        URLShorteners(intCounter2).strShortenerURL = "kissa.be"
        URLShorteners(intCounter2).strAPIURL = "http://kissa.be/api/shortener/url?content="
        intCounter2 += 1
        URLShorteners(intCounter2).strShortenerURL = "kl.am"
        URLShorteners(intCounter2).strAPIURL = "http://kl.am/api/shorten/?format=text&url="
        intCounter2 += 1
        URLShorteners(intCounter2).strShortenerURL = "krz.ch"
        URLShorteners(intCounter2).strAPIURL = "http://krz.ch/?module=ShortURL&file=Add&mode=API&url="
        intCounter2 += 1
        URLShorteners(intCounter2).strShortenerURL = "lt.tl"
        URLShorteners(intCounter2).strAPIURL = "http://lt.tl/api.php?create="
        intCounter2 += 1
        URLShorteners(intCounter2).strShortenerURL = "micurl.com"
        URLShorteners(intCounter2).strAPIURL = "http://micurl.com/api.php?url="
        URLShorteners(intCounter2).blnNeedsSpecificShorten = True
        intCounter2 += 1
        URLShorteners(intCounter2).strShortenerURL = "r.im"
        URLShorteners(intCounter2).strAPIURL = "http://r.im/api/index.cfm?long_url="
        URLShorteners(intCounter2).blnNeedsSpecificShorten = True
        intCounter2 += 1
        URLShorteners(intCounter2).strShortenerURL = "ri.ms"
        URLShorteners(intCounter2).strAPIURL = "http://ri.ms/api-create.php?url="
        URLShorteners(intCounter2).blnEncodeURL = False
        intCounter2 += 1
        URLShorteners(intCounter2).strShortenerURL = "safe.mn"
        URLShorteners(intCounter2).strAPIURL = "http://safe.mn/api/?format=text&url="
        URLShorteners(intCounter2).intLineNumber = 1
        intCounter2 += 1
        URLShorteners(intCounter2).strShortenerURL = "sai.ly"
        URLShorteners(intCounter2).strAPIURL = "http://www.sai.ly/new.txt?href="
        intCounter2 += 1
        URLShorteners(intCounter2).strShortenerURL = "short.to"
        URLShorteners(intCounter2).strAPIURL = "http://short.to/s.txt?url="
        intCounter2 += 1
        URLShorteners(intCounter2).strShortenerURL = "sn.im"
        URLShorteners(intCounter2).strAPIURL = "http://snipr.com/site/snip?snipuser=gnintendo&snipapi=f5daf489080a38375257910514b2328a&sniplink="
        URLShorteners(intCounter2).blnNeedsSpecificShorten = True
        intCounter2 += 1
        URLShorteners(intCounter2).strShortenerURL = "snurl.com"
        URLShorteners(intCounter2).strAPIURL = "http://snurl.com/site/snip?snipuser=gnintendo&snipapi=f5daf489080a38375257910514b2328a&sniplink="
        URLShorteners(intCounter2).blnNeedsSpecificShorten = True
        intCounter2 += 1
        URLShorteners(intCounter2).strShortenerURL = "tinyurl.com"
        URLShorteners(intCounter2).strAPIURL = "http://tinyurl.com/api-create.php?url="
        intCounter2 += 1
        URLShorteners(intCounter2).strShortenerURL = "to.ly"
        URLShorteners(intCounter2).strAPIURL = "http://to.ly/api.php?text=1&longurl="
        intCounter2 += 1
        URLShorteners(intCounter2).strShortenerURL = "tr.im"
        URLShorteners(intCounter2).strAPIURL = "http://api.tr.im/api/trim_simple?url="
        intCounter2 += 1
        URLShorteners(intCounter2).strShortenerURL = "u.nu"
        URLShorteners(intCounter2).strAPIURL = "http://u.nu/unu-api-simple?url="
        intCounter2 += 1
        URLShorteners(intCounter2).strShortenerURL = "unfake.it"
        URLShorteners(intCounter2).strAPIURL = "http://unfake.it/?a=api&url="
        intCounter2 += 1
        URLShorteners(intCounter2).strShortenerURL = "vi.ly"
        URLShorteners(intCounter2).strAPIURL = "http://vi.ly/api?url="
        intCounter2 += 1
        URLShorteners(intCounter2).strShortenerURL = "vl.am"
        URLShorteners(intCounter2).strAPIURL = "http://vl.am/api/shorten/plain/"
        URLShorteners(intCounter2).blnEncodeURL = False
        intCounter2 += 1
        URLShorteners(intCounter2).strShortenerURL = "vtc.es"
        URLShorteners(intCounter2).strAPIURL = "http://vtc.es/create.php?url="
        intCounter2 += 1
        URLShorteners(intCounter2).strShortenerURL = "xrl.us"
        URLShorteners(intCounter2).strAPIURL = "http://metamark.net/api/rest/simple?long_url="
        intCounter2 += 1
        URLShorteners(intCounter2).strShortenerURL = "z.pe"
        URLShorteners(intCounter2).strAPIURL = "http://api.z.pe/new.txt?href="
        URLShorteners(intCounter2).blnNeedsSpecificShorten = True
        intCounter2 += 1
        URLShorteners(intCounter2).strShortenerURL = "zz.gd"
        URLShorteners(intCounter2).strAPIURL = "http://zz.gd/api-create.php?url="
    End Sub

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        InitializeURLShorteners()
        FindEnabledShorteners()
    End Sub

    Private Sub btnShortenURL_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnShortenURL.Click
        If Me.btnShortenURL.Text <> "Stop" Then
            Me.pgsProgressBar.Value = 0
            Me.pgsProgressBar.Visible = True
            Me.lstShortenedURLs.Items.Clear()
            Me.btnShortenURL.Text = "Stop"
            strURL = Me.txtURL.Text
            thrdURLThread = New System.Threading.Thread(AddressOf GetURLS)
            thrdURLThread.IsBackground = True
            thrdURLThread.Start()
        Else
            Dim thrdAbortThread As New System.Threading.Thread(AddressOf AbortThread)
            thrdAbortThread.IsBackground = True
            thrdAbortThread.Start()
            URLThreadExiting(True)
        End If
    End Sub

    Private Sub AbortThread()
        Me.thrdURLThread.Abort()
    End Sub

    Private Sub AddURL(ByVal strURL As String, ByVal strWebsite As String)
        Dim strStringtoAdd As String
        If Len(strURL) <> 0 Then
            If strURL.StartsWith("http://") = True And strURL.Contains("<") = False Then
                strStringtoAdd = strURL
            Else
                strStringtoAdd = strWebsite & ": Error"
            End If
        Else
            strStringtoAdd = strWebsite & ": Error"
        End If
        If My.Settings.blnSortByLength = True Then
            If Me.lstShortenedURLs.Items.Count = 0 Then
                Me.lstShortenedURLs.Items.Add(strStringtoAdd)
            Else
                If strStringtoAdd.Length >= Me.lstShortenedURLs.Items.Item(Me.lstShortenedURLs.Items.Count - 1).ToString.Length Then
                    Me.lstShortenedURLs.Items.Insert(Me.lstShortenedURLs.Items.Count, strStringtoAdd)
                Else
                    For intCounter As Integer = 0 To Me.lstShortenedURLs.Items.Count - 1
                        If strStringtoAdd.Length < Me.lstShortenedURLs.Items.Item(intCounter).ToString.Length Then
                            Me.lstShortenedURLs.Items.Insert(intCounter, strStringtoAdd)
                            Exit For
                        End If
                    Next
                End If
            End If
        Else
            Me.lstShortenedURLs.Items.Add(strStringtoAdd)
        End If
        Me.lstShortenedURLs.Refresh()
        Me.pgsProgressBar.PerformStep()
    End Sub

    Private Sub txtURL_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles txtURL.DragDrop
        Me.txtURL.Text = e.Data.GetData(DataFormats.Text)
    End Sub

    Private Sub txtURL_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles txtURL.DragEnter
        If e.Data.GetDataPresent(DataFormats.Text) = True Then
            e.Effect = DragDropEffects.Copy
        End If
    End Sub

    Private Sub txtURL_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtURL.KeyDown
        If Len(Me.txtURL.Text) <> 0 Then
            If e.KeyCode = Keys.Enter Then
                e.SuppressKeyPress = True
                btnShortenURL_Click(Me.btnShortenURL, New System.EventArgs)
            End If
        End If
    End Sub

    Private Sub mnuExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuExit.Click
        Me.Close()
    End Sub

    Private Sub mnuAboutURLShortener_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuAboutURLShortener.Click
        If AboutMURLS.Created = False Then
            AboutMURLS.Show()
        Else
            AboutMURLS.Focus()
        End If
    End Sub

    Private Sub mnuHelpDialog_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuHelpDialog.Click
        MessageBox.Show("Double-click a shortened URL to copy it to your clipboard, the rest is self-explanatory.", "Help")
    End Sub

    Private Sub mnuOptions_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuOptions.Click
        If frmOptions.Created = False Then
            frmOptions.Show()
        Else
            frmOptions.Focus()
        End If
    End Sub

    Public Sub FindEnabledShorteners()
        Dim intEnabledShorteners As Integer
        For intCounter As Integer = 0 To URLShorteners.Length - 1
            If URLShorteners(intCounter).EnabledSetting = True Then
                intEnabledShorteners += 1
            End If
        Next
        Me.pgsProgressBar.Maximum = intEnabledShorteners
    End Sub

    Private Sub lstShortenedURLs_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles lstShortenedURLs.MouseDown
        If e.Button = Windows.Forms.MouseButtons.Left And e.Clicks = 1 Then
            blnMouseDown = True
        End If
    End Sub

    Private Sub lstShortenedURLs_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles lstShortenedURLs.MouseUp
        blnMouseDown = False
        If e.Clicks = 1 And e.Button = Windows.Forms.MouseButtons.Right Then
            If Me.lstShortenedURLs.IndexFromPoint(e.Location) <> -1 Then
                Me.lstShortenedURLs.SelectedIndex = Me.lstShortenedURLs.IndexFromPoint(e.Location)
                Me.cntxtCopy.Show(Me.lstShortenedURLs, e.Location)
            End If
        End If
    End Sub

    Private Sub lstShortenedURLs_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles lstShortenedURLs.MouseMove
        If blnMouseDown = True Then
            blnMouseDown = False
            If Me.lstShortenedURLs.SelectedIndex <> -1 Then
                Me.lstShortenedURLs.DoDragDrop(Me.lstShortenedURLs.SelectedItem.ToString, DragDropEffects.Copy)
            End If
        End If
    End Sub

    Private Sub GetURLS()
        For intCounter As Integer = 0 To URLShorteners.Length - 1
            If URLShorteners(intCounter).EnabledSetting = True Then
                UpdateProgress(False, URLShorteners(intCounter).strShortenerURL)
                UpdateProgress(True, URLShorteners(intCounter).ShortenURL(strURL) & "~" & URLShorteners(intCounter).strShortenerURL)
            End If
        Next
        URLThreadExiting()
    End Sub

    Private Sub URLThreadExiting(Optional ByVal blnStopped As Boolean = False)
        If Me.InvokeRequired = True Then
            Me.Invoke(New MethodInvoker(AddressOf URLThreadExiting))
        Else
            Me.btnShortenURL.Text = "Shorten URL"
            If blnStopped = False Then
                Me.lblStatus.Text = "Done"
            Else
                Me.lblStatus.Text = "Stopped"
            End If
            Me.pgsProgressBar.Visible = False
        End If
    End Sub

    Private Sub DoProgressUpdate()
        If Me.InvokeRequired = True Then
            Me.Invoke(New MethodInvoker(AddressOf DoProgressUpdate))
        Else
            If blnOperation = False Then
                Me.lblStatus.Text = "Retrieving URL from " & strUserState
            Else
                AddURL(strUserState.Substring(0, strUserState.LastIndexOf("~")), strUserState.Substring(strUserState.LastIndexOf("~") + 1))
            End If
        End If
    End Sub

    Private Sub UpdateProgress(ByVal blnOperationToPass As Boolean, ByVal strUserStateToPass As String)
        blnOperation = blnOperationToPass
        strUserState = strUserStateToPass
        DoProgressUpdate()
    End Sub

    Private Sub lstShortenedURLs_MouseDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles lstShortenedURLs.MouseDoubleClick
        If Me.lstShortenedURLs.SelectedIndex <> -1 Then
            Clipboard.SetText(Me.lstShortenedURLs.SelectedItem.ToString)
            If My.Settings.blnClipboardMessageBox = True Then
                MessageBox.Show("Successfully copied " & Me.lstShortenedURLs.SelectedItem.ToString & " to the clipboard", "Success")
            End If
        End If
    End Sub

    Private Sub mnuCheckForUpdates_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuCheckForUpdates.Click
        Dim thrdUpdateThread As System.Threading.Thread
        thrdUpdateThread = New System.Threading.Thread(AddressOf CheckForUpdates)
        thrdUpdateThread.IsBackground = True
        thrdUpdateThread.Start()
    End Sub

    Private Sub CheckForUpdates()
        Dim intCurrentVersion() As Integer = {2, 2, 4}
        Try
            Dim strLatestVersion As String() = New System.IO.StreamReader(System.Net.HttpWebRequest.Create("http://murls.googlecode.com/svn/trunk/MURLS_GUI/URL%20Shortener/update.txt").GetResponse().GetResponseStream()).ReadLine().Split(".")
            For intCounter As Integer = 0 To strLatestVersion.Length - 1
                If Val(strLatestVersion(intCounter)) > intCurrentVersion(intCounter) Then
                    Dim intInput As SByte
                    intInput = MsgBox("A new version of MURLS is available, would you like to visit the download page now?", vbYesNo, "Update Available")
                    If intInput = vbYes Then
                        System.Diagnostics.Process.Start("http://code.google.com/p/murls/downloads/list")
                    End If
                    Exit Sub
                ElseIf Val(strLatestVersion(intCounter)) < intCurrentVersion(intCounter) Then
                    Exit For
                End If
            Next
            MessageBox.Show("There are no updates available.", "No Updates Found")
        Catch ThrewError As Exception
            MessageBox.Show("Error checking for updates", "Error")
        End Try
    End Sub

    Private Sub cntxtmnuCopy_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cntxtmnuCopy.Click
        Clipboard.SetText(Me.lstShortenedURLs.SelectedItem.ToString)
        If My.Settings.blnClipboardMessageBox = True Then
            MessageBox.Show("Successfully copied " & Me.lstShortenedURLs.SelectedItem.ToString & " to the clipboard", "Success")
        End If
    End Sub

    Private Sub lstShortenedURLs_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles lstShortenedURLs.KeyDown
        If e.Modifiers = Keys.Control And e.KeyCode = Keys.C Then
            If Me.lstShortenedURLs.SelectedIndex <> -1 Then
                Clipboard.SetText(Me.lstShortenedURLs.SelectedItem.ToString)
                If My.Settings.blnClipboardMessageBox = True Then
                    strClipboardURL = Me.lstShortenedURLs.SelectedItem.ToString
                    blnKeyDown = True
                End If
            End If
        End If
    End Sub

    Private Sub lstShortenedURLs_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles lstShortenedURLs.KeyUp
        If blnKeyDown = True Then
            MessageBox.Show("Successfully copied " & strClipboardURL & " to the clipboard", "Success")
            blnKeyDown = False
        End If
    End Sub
End Class
